import { useStore } from 'src/plugins/pinia';
import { storeToRefs } from 'src/plugins/pinia/common';


export function setTheme(theme = 'light') {
	const { sys } = useStore();
	sys.$patch({ dataTheme: theme });

	// #ifdef H5
	document.querySelector('html').setAttribute('data-theme', theme);
	// #endif

	// #ifdef APP-PLUS
	// https://www.html5plus.org/doc/zh_cn/webview.html#plus.webview.WebviewObject.evalJS
	var wvs = plus.webview.all();
	var evalJs = `document.querySelector('html').setAttribute('data-theme', '${theme}')`;
	for (var i = 0; i < wvs.length; i++) {
		wvs[i].evalJS(evalJs)
	}
	// #endif
}